﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AmuTools;

namespace app.Controllers
{
    public class ApiController : Controller
    {
        public string Do()
        {
            ApiContext ac = new ApiContext {
                Url = "api/" + this.RouteData.Values.Values.First(),
                Request = Request,
                Session = Session,
                Response = Response
            };
            object result;
            try
            {
                result = ApiRegister.ah.Request(ac);
            }
            catch (ApiException e)
            {
                result = new MessageResult { status = e.Status, message = e.Message }; 
            }
            return SqlHelper.ObjToJson(result);
        }
    }
}